package com.xiaoyi.intentsdklibrary.SDK;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.Utils.StateBarUtil;

public class DrawViewSDK {
    private static final DrawViewSDK ourInstance = new DrawViewSDK();
    private Handler mHandler;
    private WindowManager.LayoutParams mParams;
    private Runnable mR;
    private View mView;
    private WindowManager mWM;

    public static DrawViewSDK getInstance() {
        return ourInstance;
    }

    private DrawViewSDK() {
    }

    public void showRectOrCircleView(Context context, int i, int i2, int i3, int i4, boolean z, int i5) {
        if (SDK.isRunning) {
            removeView();
            View view = new View(context);
            this.mView = view;
            view.setBackgroundResource(z ? R.drawable.red_circle_border : R.drawable.red_rect_border);
            this.mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            this.mParams = layoutParams;
            layoutParams.height = -2;
            this.mParams.width = -2;
            this.mParams.flags = 152;
            this.mParams.format = -3;
            this.mParams.type = 2003;
            this.mParams.gravity = 8388659;
            this.mParams.x = i;
            this.mParams.y = i2 - StateBarUtil.getStatusBarHeight(context);
            this.mParams.width = i3;
            this.mParams.height = i4;
            this.mWM.addView(this.mView, this.mParams);
            if (i5 != -1) {
                try {
                    if (this.mHandler == null) {
                        this.mHandler = new Handler();
                    }
                    Runnable runnable = this.mR;
                    if (runnable != null) {
                        this.mHandler.removeCallbacks(runnable);
                    }
                    this.mR = null;
                    Runnable r2 = new Runnable() {
                        /* class com.xiaoyi.intentsdklibrary.SDK.DrawViewSDK.AnonymousClass1 */

                        public void run() {
                            DrawViewSDK.this.removeView();
                        }
                    };
                    this.mR = r2;
                    this.mHandler.postDelayed(r2, (long) i5);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void removeView() {
        View view;
        try {
            WindowManager windowManager = this.mWM;
            if (windowManager != null && (view = this.mView) != null) {
                windowManager.removeView(view);
                this.mWM = null;
                this.mView = null;
                this.mParams = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showFloatClickView(Context context, int i, int i2, int i3) {
        if (SDK.isRunning) {
            removeView();
            this.mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            ImageView imageView = new ImageView(context);
            this.mView = imageView;
            imageView.setImageResource(R.drawable.wave);
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            this.mParams = layoutParams;
            layoutParams.flags = 152;
            this.mParams.format = -3;
            this.mParams.type = 2003;
            this.mParams.gravity = 8388659;
            this.mParams.x = i - 50;
            this.mParams.y = (i2 - 50) - StateBarUtil.getStatusBarHeight(context);
            this.mParams.width = 100;
            this.mParams.height = 100;
            this.mWM.addView(this.mView, this.mParams);
            if (i3 != -1) {
                try {
                    if (this.mHandler == null) {
                        this.mHandler = new Handler();
                    }
                    Runnable runnable = this.mR;
                    if (runnable != null) {
                        this.mHandler.removeCallbacks(runnable);
                    }
                    this.mR = null;
                    Runnable r3 = new Runnable() {
                        /* class com.xiaoyi.intentsdklibrary.SDK.DrawViewSDK.AnonymousClass2 */

                        public void run() {
                            DrawViewSDK.this.removeView();
                        }
                    };
                    this.mR = r3;
                    this.mHandler.postDelayed(r3, (long) i3);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
